<template>
  <view class="address">
    <!-- 添加收货人 -->
    <view class="add-address" v-if="JSON.stringify(user) === '{}'"><button class="receivingAddress" @click="addAddress">请选择收货地址+</button></view>
    <!-- 收货人简略信息 -->
    <view class="address-info-box" v-else @click="addAddress">
      <view class="row1">
        <view class="user-name">收货人:{{ user.userName }}</view>
        <view class="phone">电话:{{ user.telNumber }}</view>
      </view>
      <view class="row2">
        <view class="row2-left">收货地址:</view>
        <view class="row2-right">{{ addstr }}</view>
      </view>
    </view>
  </view>
</template>
<script>
import { mapState, mapGetters } from 'vuex';
export default {
  data() {
    return {};
  },
  methods: {
    async addAddress() {
      const [err, succ] = await uni.chooseAddress().catch(err => err);
      if (err === null && succ.errMsg === 'chooseAddress:ok') {
        this.address = succ;
        this.$store.commit('user/saveUser', succ);
      }
    }
  },
  computed: {
    ...mapState('user', ['user']),
    ...mapGetters('user', ['addstr'])
  }
};
</script>
<style lang="scss">
.address {
  border-bottom: 5px dashed #000;
  .add-address {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 90px;
    .receivingAddress {
      height: 30px;
      border-radius: 5px;
      background-color: seagreen;
      text-align: center;
      line-height: 30px;
      padding: 0px 10px;
    }
  }
}
.address-info-box {
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 90px;
  font-size: 12px;
  padding: 0px 10px;
  .row1 {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .row2 {
    display: flex;
    align-items: center;
    margin-top: 10px;
    .row2-left {
      white-space: nowrap;
    }
    .row2-right {
      margin-left: 5px;
    }
  }
}
</style>
